use core::u16;

use cfw_kit::ota::IDLE_ADDR;
use cfw_kit::store::{Reset, Store};
use cmsis_rtos2_rs::static_mem::MutexValue;

pub mod ctrl;
pub mod motor;
pub mod nozzle_motor;
pub mod sensor;
pub mod temperature;
pub mod ice_uart;

#[derive(Clone, Copy)]
pub struct AppInfo {
    pub water_temp: i16,      // 热水锅炉加热温度
    pub steam_temp: i16, // 蒸汽温度

    pub draw_water_timeout: u16, // 秒

    pub water_heat_timeout: u16, // 秒
    pub steam_heat_timeout: u16,

    pub flow_1000l_puls_count: u16,
}

impl Reset for AppInfo {
    fn reset(&mut self) {
        self.water_temp = 80;
        self.steam_temp = 120;

        self.draw_water_timeout = 1800;
        self.steam_heat_timeout = 120;
        self.water_heat_timeout = 1800;
        self.flow_1000l_puls_count = 1000;
    }
}

pub type AppStore = Store<AppInfo, IDLE_ADDR>;

pub static APP_INFO: MutexValue<AppStore> = MutexValue::uninit(AppStore::const_new(AppInfo {
    water_temp: 0,
    steam_temp: 0,
    draw_water_timeout: 0,
    water_heat_timeout: 0,
    steam_heat_timeout: 0,
    flow_1000l_puls_count: 100,
}));

pub unsafe fn init() {
    APP_INFO.init_once("app_info");
    ctrl::init();
    motor::init();
    nozzle_motor::init();
    sensor::init();
    temperature::init();
    ice_uart::init();
}
